#pragma once
#include <vector>
#include <string>
#include <functional>
#include "../Headers/types.h"
#include "gui.window.h"

namespace TOB {
  class UIMenu: public UIWindow {
   public:
    UIMenu(uint16 x, uint16 y, uint16 w, uint16 h);
    ~UIMenu();

    /**
     *  UI Menu Item
     */
    typedef struct {
      typedef std::function<void()> Handler;
      String title;
      Handler handler;
    } Item;

    /**
     *  Insert new item
     *
     *  @param title Title of item
     *  @param handler Select event handler
     *  @return Newely created item
     */
    Item *insert(String title, Item::Handler handler);

    /**
     *  Set focus
     */
    void focus();

    /**
     *  Print current state
     */
    void print();

    /**
     *  Select next item
     */
    void next();

    /**
     *  Select previous item
     */
    void prev();

    /**
     *  Status
     */
    bool running;

    /**
     *  Draw rest of item
     */
    bool drawRest;

   protected:
    uint16 y;
    uint32 selected, scrollY;
    std::vector<Item*> items;
  };
}
